package wiki.zimo.domain;

import java.util.Objects;

/**
 * @version v1.0
 * @auther: 子墨
 * @datetime: 2018/11/4 22:11
 * @description: 购物车中每一项实体类
 */
public class CartItem {
    private Product product;// 商品
    private double subTotal;// 金额小计
    private int count;// 数目

    public CartItem(Product product, Integer count) {
        this.product = product;
        this.count = count;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public double getSubTotal() {
        subTotal = product.getShop_price() * count;
        return subTotal;
    }

    public void setSubTotal(double subTotal) {
        this.subTotal = subTotal;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CartItem cartItem = (CartItem) o;
        return Double.compare(cartItem.subTotal, subTotal) == 0 &&
                count == cartItem.count &&
                Objects.equals(product, cartItem.product);
    }

    @Override
    public int hashCode() {

        return Objects.hash(product, subTotal, count);
    }

    @Override
    public String toString() {
        return "CartItem{" +
                "product=" + product +
                ", subTotal=" + subTotal +
                ", count=" + count +
                '}';
    }
}
